﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.Web.SessionState;
using DTcms.Web.UI;
using DTcms.Common;

namespace DTcms.Web.m
{
    /// <summary>
    /// rz_list 的摘要说明
    /// </summary>
    public class rz_list : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            int category_id = DTRequest.GetQueryInt("category_id", 0);
            int quanzi_id = DTRequest.GetQueryInt("quanzi_id", 1);

            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");
            //获取供应信息
            BLL.company bll = new BLL.company();
            string strWhere = string.Empty;
            if (category_id > 0)
            {
                strWhere = "rz_category_id=" + category_id;
            }
            else
            {
                strWhere = "rz_category_id>0";
            }
            DataSet ds = bll.GetList(0, strWhere + " and quanzi_id=" + quanzi_id, "id desc");
            //如果记录存在
            if (ds.Tables[0].Rows.Count > 0)
            {
                strTxt.Append("\"rz_list\":[");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr3 = ds.Tables[0].Rows[i];
                    strTxt.Append("{");
                    strTxt.Append("\"id\":" + dr3["id"]);
                    strTxt.Append(",\"title\":\"" + dr3["title"] + "\"");
                    strTxt.Append(",\"mobile\":\"" + dr3["mobile"] + "\"");
                    strTxt.Append(",\"pro_remark\":\"" + Microsoft.JScript.GlobalObject.escape(dr3["pro_remark"].ToString()) + "\"");
                    if (string.IsNullOrEmpty(dr3["logo"].ToString()))
                    {
                        strTxt.Append(",\"logo\":\"../image/error-img.png\"");
                    }
                    else
                    {
                        if (dr3["logo"].ToString().Contains("shicaiquanzi"))
                        {
                            if (dr3["logo"].ToString().Contains("http://")) { strTxt.Append(",\"logo\":\"" + dr3["logo"].ToString() + "\""); }
                            else { strTxt.Append(",\"logo\":\"http://" + dr3["logo"].ToString() + "\""); }
                        }
                        else
                        {
                            strTxt.Append(",\"logo\":\"http://pic.shicaiquanzi.com" + dr3["logo"].ToString() + "\"");
                        }
                        //strTxt.Append(",\"logo\":\"http://" + dr3["logo"] + "\"");
                    }
                    string rz_img = dr3["rz_imgurl"].ToString();
                    if (string.IsNullOrEmpty(rz_img))
                    {
                        strTxt.Append(",\"rz_img\":\"../image/error-img.png\"");
                    }
                    else
                    {
                        strTxt.Append(",\"rz_img\":\"http://pic.shicaiquanzi.com" + rz_img + "\"");
                    }
                    strTxt.Append("}");
                    //是否加逗号
                    if (i < ds.Tables[0].Rows.Count - 1)
                    {
                        strTxt.Append(",");
                    }
                }
                strTxt.Append("]");
            }
            else
            {
                strTxt.Append("\"status\":2,\"rz_list\":[]");
            }
            strTxt.Append("}");

            context.Response.Write(strTxt.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}